﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using Excel = Microsoft.Office.Interop.Excel;
namespace BOW
{
    public partial class ShowFormat : Form
    {
        public ShowFormat()
        {
            InitializeComponent();
        }
        ConnectDB connect = new ConnectDB();
        Common commo = new Common();
        string path = "";
        private void button1_Click(object sender, EventArgs e)
        {
           
            DataTable test = connect.getDataFromXLS(path);
            if (test != null)
                dataGridView1.DataSource = test;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            List<int> getColumns = new List<int>();
            getColumns = commo.disField(path);
            checkedListBox1.Items.Clear();
            var items = checkedListBox1.Items;
            DataTable test = connect.getDataFromXLS(path);
            if (test != null)
            {
                foreach (DataColumn item in test.Columns)
                {
                    // check columns not empty
                        if (getColumns.Contains(item.Ordinal))
                            continue;
                        else
                            items.Add(string.Format("{0}", item));
                }
            }
                
        }

        private void button3_Click(object sender, EventArgs e)
        {
            EnterQuery en = new EnterQuery();
            UpdateBOW ub = new UpdateBOW();
            DialogResult dr = new DialogResult();
            dr = DialogResult.No;
            if (commo.checkFileSize() == false)
            {
                dr = MessageBox.Show("Please update bag of words...", "Note", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dr == DialogResult.Yes)
                    ub.Show();   
            }
          
            if (commo.checkFileSize() == true || dr==DialogResult.No)
            {
                var items = checkedListBox1.Items;
                foreach (object item in checkedListBox1.CheckedItems)
                {
                    if (en.a != "")
                    {
                        en.a += "_" + item.ToString();
                    }
                    else
                        en.a = item.ToString();
                }
                if (checkedListBox1.CheckedItems.Count > 0)
                {
                    en.path = path;
                    en.ShowDialog();

                }
                else MessageBox.Show("Choose field to check dulicate !");
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            string File = openFileDialog1.FileName;
            if (string.IsNullOrEmpty(File))
                return;
            txtPath.Text = File;
            if (txtPath.Text != "")
            {
                path = txtPath.Text;
                button1.Enabled = true;
                button2.Enabled = true;
                button3.Enabled = true;
                button5.Enabled = true;
            }
        }

        private void VisbleButton()
        {
            button1.Enabled = false;
            button2.Enabled = false;
            button3.Enabled = false;
            button5.Enabled = false;
        }

        private void ShowFormat_Load(object sender, EventArgs e)
        {
            VisbleButton();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            UpdateBOW ub = new UpdateBOW();
            ub.Show();
        }
    }

}

